﻿@model GameCode.Models.Admin.GameProjectEditModel
@{
    ViewBag.Title = "游戏特权 - 游戏项目";
    Model.Caption = Model.IsNew ? "新增游戏项目" : "编辑游戏项目";
    Layout = "~/Views/Shared/_AdminLayout.cshtml";
}
<link href="@Url.Content("~/Scripts/ueditor/themes/default/ueditor.css")" rel="stylesheet" type="text/css" />
<script src="@Url.Content("~/Scripts/ueditor/editor_config.js")" type="text/javascript"></script>
<script src="@Url.Content("~/Scripts/ueditor/editor_ui_all_min.js")" type="text/javascript"></script>
<script type="text/javascript">
    var editor;
    var hasRun = false;
    var i = 0;
    $(document).live('pageshow', function (event, ui) {
        i++;
        var isReturn = $(".isReturn").val();
        if (isReturn == 'true' && i == 1) {
            return;
        }
        if (hasRun) {
            return;
        }
        $('#editor').hide();

        editor = new baidu.editor.ui.Editor({
            UEDITOR_HOME_URL: '../../Scripts/ueditor/',
            iframeCssUrl: '../../Scripts/ueditor/themes/default/iframe.css',
            autoClearinitialContent: true,
            initialContent: '<span style="color:#ccc">请输入内容</span>',
            elementPathEnabled: false,
            minFrameHeight: 400
        });
        editor.render('editor');
        if ($(".content").attr("value") != "") {
            var str = $(".content").attr("value");
            editor.setContent(str);
        }


        $('#editor').show();

        $("#uploadify").uploadify({
            'uploader': '@Url.Content("~/Scripts/uploadify/uploadify.swf")',
            'script': '@Url.Content("~/Admin/UploadHandle")',
            'cancelImg': '@Url.Content("~/Scripts/uploadify/cancel.png")',
            'folder': 'upload_files',
            'queueID': 'fileQueue',
            'auto': false,
            'multi': false,
            'wmode': 'transparent',
            'sizeLimit': 10737418240,
            'onComplete': function (e, queueId, fileObj, response, data) {
                $(".input_url").val("/upload_files/" + fileObj.name);
                $("#urll").val("/upload_files/" + fileObj.name);
                parent.reloadImg("/upload_files/" + fileObj.name);
            },
            'onError': function (a, b, c, d) {
                if (d.status == 404)
                    alert('Could not find upload script. Use a path relative to: ' + '<?= getcwd() ?>');
                else if (d.type === "HTTP")
                    alert('error ' + d.type + ": " + d.status);
                else if (d.type === "File Size")
                    alert(c.name + ' ' + d.type + ' Limit: ' + Math.round(d.sizeLimit / 1024) + 'KB');
                else
                    alert('error ' + d.type + ": " + d.text);
            }
        });
        hasRun = true;
    });
    function sumbit() {
        changeGameType();
        $(".content").attr("value", editor.getContent());
        $("form").submit();
    }
    function changeGameType() {
        var str = "";
        $(".gameType").each(function () {
            if ($(this).attr("checked") == "checked") {
                if (str == "") {
                    str += $(this).attr("id");
                }
                else {
                    str += "," + $(this).attr("id");
                }
            }
        });
        $("#gameType").val(str);
    }
</script>
@using (Html.BeginForm(new { act = "submit" }))
{
    @Html.HiddenFor(m => m.IsNew)
    @Html.HiddenFor(m => m.ID)
    <div class="ui-bar ui-bar-a">
        编辑
    </div>
    <div class="ui-body ui-body-a">
        @if (!Model.IsNew)
        { 
            <div data-role="fieldcontain">
                @Html.LabelFor(m => m.ProjectNr)
                @Html.DisplayFor(m => m.ProjectNr, new Dict() { "data-mini:true" })
            </div>
        }
        <div data-role="fieldcontain">
            @Html.LabelFor(m => m.GameName)
            @Html.TextBoxFor(m => m.GameName, new Dict() { "data-mini:true" })
            @Html.ValidationMessageFor(m => m.GameName, new { style = "color:Red" })
        </div>
        <div data-role="fieldcontain">
            @Html.LabelFor(m => m.WebSite)
            @Html.TextBoxFor(m => m.WebSite, new Dict() { "data-mini:true" })
            @Html.ValidationMessageFor(m => m.WebSite, new { style = "color:Red" })
        </div>
        <div data-role="fieldcontain">
            @Html.LabelFor(m => m.GameDescription)
            @Html.TextAreaFor(m => m.GameDescription, new Dict() { "data-mini:true" })
            @Html.ValidationMessageFor(m => m.GameDescription, new { style = "color:Red" })
        </div>
        <div data-role="fieldcontain">
            @Html.LabelFor(m => m.LogoLink)
            @Html.TextBoxFor(m => m.LogoLink, new Dict() { "data-mini:true", "class:input_url" })
            @Html.ValidationMessageFor(m => m.LogoLink, new { style = "color:Red" })
        </div>
        <div data-role="fieldcontain">
            @Html.Partial("Upload")
        </div>
        <div data-role="fieldcontain">
            <label for="GameType" class="ui-input-text">游戏类型：</label>
            @Html.HiddenFor(m => m.GameType, new { id = "gameType" })
            <div data-role="controlgroup" data-type="horizontal" class="controlgroup_fieldset">
                @for (int i = 0; i < Model.GameTypeList.Count; i++)
                { 
@*<input type="checkbox" data-theme="a" name="@Model.GameTypeList[i].ID" class="gameType" id="@Model.GameTypeList[i].ID" onclick="changeGameType()" />*@
                    @Html.CheckBoxFor(m => m.GameTypeList[i].IsSelect, new Dict() {"data-theme:a", "name:" + @Model.GameTypeList[i].ID, "id:" + @Model.GameTypeList[i].ID, "class:gameType" })
                    <label for="@Model.GameTypeList[i].ID">@Model.GameTypeList[i].Name</label>
                }
            </div>
            @Html.ValidationMessageFor(m => m.GameType, new { style = "color:Red" })
        </div>
        <div data-role="fieldcontain">
            @Html.LabelFor(m => m.ProjectName)
            @Html.TextBoxFor(m => m.ProjectName, new Dict() { "data-mini:true" })
            @Html.ValidationMessageFor(m => m.ProjectName, new { style = "color:Red" })
        </div>
        <div data-role="fieldcontain">
            @Html.LabelFor(m => m.RightName)
            @Html.TextAreaFor(m => m.RightName, new Dict() { "data-mini:true" })
            @Html.ValidationMessageFor(m => m.RightName, new { style = "color:Red" })
        </div>
        <div data-role="fieldcontain">
            @Html.LabelFor(m => m.Operator)
            @Html.TextBoxFor(m => m.Operator, new Dict() { "data-mini:true" })
            @Html.ValidationMessageFor(m => m.Operator, new { style = "color:Red" })
        </div>
        <div data-role="fieldcontain">
            @Html.LabelFor(m => m.OperateState)
            @Html.TextBoxFor(m => m.OperateState, new Dict() { "data-mini:true" })
            @Html.ValidationMessageFor(m => m.OperateState, new { style = "color:Red" })
        </div>
        <div data-role="fieldcontain">
            @Html.LabelFor(m => m.ServerName)
            @Html.TextBoxFor(m => m.ServerName, new Dict() { "data-mini:true" })
            @Html.ValidationMessageFor(m => m.ServerName, new { style = "color:Red" })
        </div>
        <div data-role="fieldcontain">
            @Html.LabelFor(m => m.OpenDate)
            @Html.TextBoxFor(m => m.OpenDate, new Dict() { "data-mini:true" })
            @Html.ValidationMessageFor(m => m.OpenDate, new { style = "color:Red" })
        </div>
        @Html.HiddenFor(m => m.GiftContent, new { @class = "content" })
        <div data-role="fieldcontain">
            <div id='editor'>
            </div>
        </div>
        <div data-role="fieldcontain">
            @Html.CheckBoxFor(m => m.Effective, new Dict() { "data-mini:true" })
            @Html.LabelFor(m => m.Effective)
            @Html.ValidationMessageFor(m => m.Effective, new { style = "color:Red" })
        </div>
        <div data-role="fieldcontain">
            @Html.LabelFor(m => m.Seq)
            @Html.TextBoxFor(m => m.Seq, new Dict() { "data-mini:true" })
            @Html.ValidationMessageFor(m => m.Seq, new { style = "color:Red" })
        </div>
        <input type="button" value="确认" data-inline="true" data-mini="true" onclick="sumbit()" />
    </div>
}